<?php


namespace app\voip\func;


use app\voip\model\EAirlinesLog;
use app\voip\model\ECultural;

class AirlinesLogFunc
{
    /**
     * @param $id
     * @param $type
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function getLogList($id, $type)
    {
        $obj=new EAirlinesLog();
        return $obj->alias('e1')->join('admin a1','e1.aid=a1.id')->join('e_call_task t1','e1.tid=t1.id')->
        where(['e1.uid'=>$id,'e1.type'=>$type])->field('a1.nickname,e1.*,t1.aim aimname')
            ->limit(0,config('callLogLimit'))->
            order('e1.id desc')->select();
    }

    /**
     * @param $data
     * @return bool
     */
    static public function uploadLog($data)
    {
        $obj =new EAirlinesLog($data);
        return $obj->allowField(true)->save();
    }

    /**
     * @param $where
     * @return EAirlinesLog|null
     * @throws \think\exception\DbException
     */
    static public function findLog($where)
    {

        $obj = new EAirlinesLog();
        return $obj->where($where)->order('id desc')->find();
    }

    /**
     * 客服查看日志
     * @param $where
     * @param $order
     * @return EAirlinesLog[]|false
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function aLoginList($where,$order)
    {
        $obj = new EAirlinesLog();
        return $obj->alias('a1')->join('admin a2','a1.aid=a2.id')->join('e_call_task c1','a1.tid=c1.id')->where($where)->field('a1.*,a2.nickname,c1.aim,c1.name taskname')->order($order)->select();
    }

    /**
     * 获取文化
     * @param $id
     * @return ECultural|null
     * @throws \think\exception\DbException
     */
    static public function getCultural($id)
    {
        return ECultural::get(['id'=>$id]);
    }
}